//
//  KKStatusToolBar.swift
//  KKWeibo
//
//  Created by kassia on 16/7/14.
//  Copyright © 2016年 kassia. All rights reserved.
//

import UIKit
/// toolBar视图
class KKStatusToolBar: UIView {

    /// 懒加载控件f
    private lazy var retweetButton: UIButton = self.addChildToolBar("转发", imageName: "timeline_icon_retweet") // 转发按钮
    
    private lazy var commentButton: UIButton = self.addChildToolBar("评论", imageName: "timeline_icon_comment") // 评论按钮
    
    private lazy var unlikeButton: UIButton = self.addChildToolBar("赞", imageName: "timeline_icon_unlike") // 点赞按钮
    
    var statusViewModel: KKStatusViewModel? {
    
        didSet {
        
            retweetButton.setTitle(statusViewModel?.retweetStr, forState: .Normal)
            commentButton.setTitle(statusViewModel?.commentStr, forState: .Normal)
            unlikeButton.setTitle(statusViewModel?.unlikeStr, forState: .Normal)
            
        
        }
    
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUpUI() {
     
        
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
        }
        
    }
    
    private func addChildToolBar(name: String, imageName: String) -> UIButton {
        
        let button = UIButton()
        
        button.setImage(UIImage(named: imageName), forState: .Normal) // 设置图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal) // 背景颜色
        button.adjustsImageWhenHighlighted = false // 取消高亮
        button.setTitle(name, forState: .Normal) //设置文字
        button.setTitleColor(UIColor.grayColor(), forState: .Normal) // 设置颜色
        button.titleLabel?.font = UIFont.systemFontOfSize(15)

        //添加按钮
        addSubview(button)

        return button
        
    }
    


}
